﻿var AnJuKeAdvertEdit = {};
$(function () {
    $("#selExposure").val($("#selExposure").attr("bindvalue"));
    //实例化编辑器
    var um = UM.getEditor('desc');
    $("#txtTitle").bind("blur", checkTitle);
    $("#desc").bind("blur", checkDesc);
    //var roomPhotosSetting = {
    //    flash_url: "/Scripts/PageHelper/swfupload.swf",
    //    upload_url: $("#uploadPath").val(),
    //    post_params: {},
    //    file_size_limit: "4 MB",
    //    file_types: "*.jpeg;*.jpg;*.gif;*.png",
    //    file_types_description: "JPG Images",
    //    file_upload_limit: 30,
    //    file_queue_limit: 30,
    //    custom_settings: {
    //        progressTarget: "fsUploadProgress",
    //        thumbnail_height: 1440,
    //        thumbnail_width: 1440,
    //        thumbnail_quality: 100
    //    },
    //    debug: false,
    //    // Button settings
    //    button_image_url: "",
    //    button_width: "108",
    //    button_height: "20",
    //    button_placeholder_id: "uploadRoomImg",
    //    button_cursor: SWFUpload.CURSOR.HAND,
    //    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
    //    button_text: '<span class="blue">本地上传</span>',
    //    button_text_style: ".blue{color:#1f73f0;}",
    //    button_text_left_padding: 12,
    //    button_text_top_padding: 3,

    //    // The event handler functions are defined in handlers.js
    //    file_queue_error_handler: fileQueueErrorRoomPhotos,
    //    file_dialog_complete_handler: fileDialogComplete,
    //    upload_start_handler: uploadStart,
    //    upload_progress_handler: uploadProgress,
    //    upload_error_handler: uploadError,
    //    upload_success_handler: uploadSuccessRoomPhotos,
    //    upload_complete_handler: uploadComplete,
    //    queue_complete_handler: queueComplete,	// Queue plugin event

    //};


    //roomPhotosUpload = new SWFUpload(roomPhotosSetting);

    //var roomTypeSetting = {
    //    flash_url: "/Scripts/PageHelper/swfupload.swf",
    //    upload_url: $("#uploadPath").val(),
    //    post_params: {},
    //    file_size_limit: "4 MB",
    //    file_types: "*.jpeg;*.jpg;*.gif;*.png",
    //    file_types_description: "JPG Images",
    //    file_upload_limit: 30,
    //    file_queue_limit: 30,
    //    custom_settings: {
    //        progressTarget: "fsUploadProgress",
    //        thumbnail_height: 1440,
    //        thumbnail_width: 1440,
    //        thumbnail_quality: 100
    //    },
    //    debug: false,

    //    // Button settings
    //    button_image_url: "",
    //    button_width: "108",
    //    button_height: "20",
    //    button_placeholder_id: "uploadRoomTypeImg",
    //    button_cursor: SWFUpload.CURSOR.HAND,
    //    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
    //    button_text: '<span class="blue">本地上传</span>',
    //    button_text_style: ".blue{color:#1f73f0;}",
    //    button_text_left_padding: 12,
    //    button_text_top_padding: 3,

    //    // The event handler functions are defined in handlers.js    
    //    file_queue_error_handler: fileQueueErrorHuXingType,
    //    file_dialog_complete_handler: fileDialogComplete,
    //    upload_start_handler: uploadStart,
    //    upload_progress_handler: uploadProgress,
    //    upload_error_handler: uploadError,
    //    upload_success_handler: RoomTypeUploadSuccess,
    //    upload_complete_handler: uploadComplete,
    //    queue_complete_handler: queueComplete	// Queue plugin event
    //};
    //roomTypeUpload = new SWFUpload(roomTypeSetting);
    function EstateUploadSuccess(file, serverData) {
        try {
            var progress = new FileProgress(file, this.customSettings.progressTarget);
            var estatePhotosCount = 0;
            progress.setComplete();
            progress.setStatus("Complete.");
            progress.toggleCancel(false);
            var arrPhotoTypes = $("input[name='AdvertPhotoType']");
            var photoTypes = new Array();
            for (var i = 0; i < arrPhotoTypes.length; i++) {
                if (arrPhotoTypes[i].value == "小区图") {
                    photoTypes.push(arrPhotoTypes[i].value);
                }
            }
            if (photoTypes.length < 10) {
                //var innerhtml = "<div class='up-pic'><input type='hidden' name='xqimg' value='" + serverData + "' /><img src='" + serverData + "?width=120&height=100&mode=stretch' alt='标题' width='120' height='100' class='l' /><div class='ml10 l'><div><a class='r aui_close' href='javascript:;' onclick='var delhxt=$(this);$.OKCancelDialogAgency(\"<div class=" + "tc" + ">您确定要删除此照片？</div>\",\"提示\",true,function(){delhxt.parent().parent().parent().remove();});'>x</a><select class='select' name='xqimgtype'>" + temstr + "</select></div><h5>照片描述：</h5><p><textarea name='xqimgtext' class='text-area' style='color:gray;' onclick=\"if(this.value=='请输入50字以内'){this.value='';this.style.color='black';}\" onblur=\"if(this.value==''){this.value='请输入50字以内';this.style.color='gray';}\" maxlength=\"50\">请输入50字以内</textarea></p><em class='close'></em></div>";
                var innerhtml = '<li><input type="hidden" name="AdvertPhotoPath" value="' + other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData) + '" /><input type="hidden" name="AdvertPhotoType" value="小区图" /><img src="' + other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData) + '?width=120&height=100&mode=stretch" alt="标题" width="120" height="100" /><span onclick="delhxt(this);" class="delhxt">×</span><a href="javascript:void(0);" onclick="setDefault(this);">设置橱窗</a><input name="AdvertIsDefault" type="hidden" value="0"/></li>';
                $(".upload-property-pics-r p").hide();
                $("#uploadRoomTypeDiv").append(innerhtml);
            }
            if (photoTypes.length + 1 > 10) {
                //AnJuKeAdvertEdit.estatePhotosCount = AnJuKeAdvertEdit.estatePhotosCount + 1;
                //$.OKDialogAgency('<div class="tc">小区图只能存在十张，如要上传请删除已存在图片！</div>');
                $.dialog({
                    id: "uploadRoomImg21",
                    lock: true,
                    ok: true,
                    content: '<center>小区图只能存在十张，如要上传请删除已存在图片！</center>'
                });
                return false;
            }
        } catch (ex) {
            this.debug(ex);
        }
    }

    function RoomTypeUploadSuccess(file, serverData) {
        try {
            var progress = new FileProgress(file, this.customSettings.progressTarget);
            progress.setComplete();
            progress.setStatus("Complete.");
            progress.toggleCancel(false);
            var arrPhotoTypes = $("input[name='AdvertPhotoType']");
            var photoTypes = new Array();
            for (var i = 0; i < arrPhotoTypes.length; i++) {
                if (arrPhotoTypes[i].value == "户型图") {
                    photoTypes.push(arrPhotoTypes[i].value);
                }
            }
            if (photoTypes.length < 4) {
                //var innerhtml = "<div class='up-pic'><input type='hidden' name='xqimg' value='" + serverData + "' /><img src='" + serverData + "?width=120&height=100&mode=stretch' alt='标题' class='l' width='120' height='100' /><div class='ml10 l'><div><a class='r aui_close' href='javascript:;' onclick='var delhxt=$(this);$.OKCancelDialogAgency(\"<div class=" + "tc" + ">您确定要删除此照片？</div>\",\"提示\",true,function(){delhxt.parent().parent().parent().remove();});'>x</a><select class='select' name='xqimgtype'>" + temstr + "</select></div><h5>照片描述：</h5><p><textarea name='xqimgtext' class='text-area' style='color:gray;' onclick=\"if(this.value=='请输入50字以内'){this.value='';this.style.color='black';}\" onblur=\"if(this.value==''){this.value='请输入50字以内';this.style.color='gray';}\" maxlength=\"50\">请输入50字以内</textarea></p><em class='close'></em></div>";
                var innerhtml = '<li><input type="hidden" name="AdvertPhotoPath" value="' + other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData) + '" /><input type="hidden" name="AdvertPhotoType" value="户型图" /><img src="' + other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData) + '?width=120&height=100&mode=stretch" alt="标题" width="120" height="100" /><span onclick="delhxt(this);" class="delhxt">×</span><a href="javascript:void(0);" onclick="setDefault(this);">设置橱窗</a><input name="AdvertIsDefault" type="hidden" value="0"/></li>';
                $(".upload-property-pics-r p").hide();
                $("#uploadRoomTypeDiv").append(innerhtml);
            }
            if (photoTypes.length + 1 > 4) {
                //$.OKDialogAgency('<div class="tc">房型图只能存在四张，如要上传请删除已存在图片！</div>');
                $.dialog({
                    id: "uploadRoomTypeImg1",
                    lock: true,
                    ok: true,
                    content: '<center>房型图只能存在四张，如要上传请删除已存在图片！</center>'
                });
                return false;
            }
        } catch (ex) {
            this.debug(ex);
        }
    }
    //上传室内图成功后调用方法
    function uploadSuccessRoomPhotos(file, serverData) {
        try {
            var progress = new FileProgress(file, this.customSettings.progressTarget);
            progress.setComplete();
            progress.setStatus("Complete.");
            progress.toggleCancel(false);
            var arrPhotoTypes = $("input[name='AdvertPhotoType']");
            var photoTypes = new Array();
            for (var i = 0; i < arrPhotoTypes.length; i++) {
                if (arrPhotoTypes[i].value == "室内图") {
                    photoTypes.push(arrPhotoTypes[i].value);
                }
            }
            if (photoTypes.length < 10) {
                var innerhtml = '<li><input type="hidden" name="AdvertPhotoPath" value="' + other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData) + '" /><input type="hidden" name="AdvertPhotoType" value="室内图" /><img src="' + other.getFullPhotoPath($("#hidImageDownloadUrl").val(), serverData) + '?width=120&height=100&mode=stretch" alt="标题" width="120" height="100" /><span onclick="delhxt(this);" class="delhxt">×</span><a href="javascript:void(0);" onclick="setDefault(this);">设置橱窗</a><input name="AdvertIsDefault" type="hidden" value="0"/></li>';
                $(".upload-property-pics-r p").hide();
                $("#uploadRoomTypeDiv").append(innerhtml);
            }
            if (photoTypes.length + 1 > 10) {
                //AnJuKeAdvertEdit.roomPhotosCount = AnJuKeAdvertEdit.roomPhotosCount + 1;
                //$.OKDialogAgency('<div class="tc">室内图只能存在十张，如要上传请删除已存在图片！</div>');
                $.dialog({
                    id: "uploadRoomImg1",
                    lock: true,
                    ok: true,
                    content: '<center>室内图只能存在十张，如要上传请删除已存在图片！</center>'
                });
                return false;
            }
        } catch (ex) {
            this.debug(ex);
        }
    }

    function fileQueueErrorRoomPhotos(file, errorCode, message) {
        try {
            var progress = new FileProgress(file, this.customSettings.progressTarget);
            progress.setError();
            progress.toggleCancel(false);

            switch (errorCode) {
                case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                    progress.setStatus("上传文件必须小于4M");
                    this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                    progress.setStatus("Cannot upload Zero Byte files.");
                    this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
                    progress.setStatus("Invalid File Type.");
                    this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
                    progress.setStatus("室内图只允许上传10张！");
                    this.debug("Error Code: File too more, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                default:
                    if (file !== null) {
                        progress.setStatus("Unhandled Error");
                    }
                    this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
            }
        } catch (ex) {
            this.debug(ex);
        }
    }

    function fileQueueErrorHuXingType(file, errorCode, message) {
        try {
            var progress = new FileProgress(file, this.customSettings.progressTarget);
            progress.setError();
            progress.toggleCancel(false);
            switch (errorCode) {
                case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                    progress.setStatus("上传文件必须小于4M");
                    this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                    progress.setStatus("Cannot upload Zero Byte files.");
                    this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
                    progress.setStatus("Invalid File Type.");
                    this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
                    progress.setStatus("房型图只允许上传4张！");
                    this.debug("Error Code: File too more, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                default:
                    if (file !== null) {
                        progress.setStatus("Unhandled Error");
                    }
                    this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
            }
        } catch (ex) {
            this.debug(ex);
        }
    }

    function fileQueueErrorXiaoQuType(file, errorCode, message) {
        try {
            var progress = new FileProgress(file, this.customSettings.progressTarget);
            progress.setError();
            progress.toggleCancel(false);

            switch (errorCode) {
                case SWFUpload.QUEUE_ERROR.FILE_EXCEEDS_SIZE_LIMIT:
                    progress.setStatus("上传文件必须小于4M");
                    this.debug("Error Code: File too big, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                case SWFUpload.QUEUE_ERROR.ZERO_BYTE_FILE:
                    progress.setStatus("Cannot upload Zero Byte files.");
                    this.debug("Error Code: Zero byte file, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                case SWFUpload.QUEUE_ERROR.INVALID_FILETYPE:
                    progress.setStatus("Invalid File Type.");
                    this.debug("Error Code: Invalid File Type, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                case SWFUpload.QUEUE_ERROR.QUEUE_LIMIT_EXCEEDED:
                    progress.setStatus("小区图只允许上传10张！");
                    this.debug("Error Code: File too more, File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
                default:
                    if (file !== null) {
                        progress.setStatus("Unhandled Error");
                    }
                    this.debug("Error Code: " + errorCode + ", File name: " + file.name + ", File size: " + file.size + ", Message: " + message);
                    break;
            }
        } catch (ex) {
            this.debug(ex);
        }
    }

    //var settings = {
    //    flash_url: "/Scripts/PageHelper/swfupload.swf",
    //    upload_url: $("#uploadPath").val(),
    //    post_params: {},
    //    file_size_limit: "4 MB",
    //    file_types: "*.jpeg;*.jpg;*.gif;*.png",
    //    file_types_description: "JPG Images",
    //    file_upload_limit: 30,
    //    file_queue_limit: 30,
    //    custom_settings: {
    //        progressTarget: "fsUploadProgress",
    //        thumbnail_height: 1440,
    //        thumbnail_width: 1440,
    //        thumbnail_quality: 100
    //    },
    //    debug: false,

    //    // Button settings
    //    button_image_url: "",
    //    button_width: "108",
    //    button_height: "20",
    //    button_placeholder_id: "uploadRoomImg2",
    //    button_cursor: SWFUpload.CURSOR.HAND,
    //    button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
    //    button_text: '<span class="blue">本地上传</span>',
    //    button_text_style: ".blue{color:#1f73f0;}",
    //    button_text_left_padding: 12,
    //    button_text_top_padding: 3,

    //    // The event handler functions are defined in handlers.js
    //    file_queue_error_handler: fileQueueErrorXiaoQuType,
    //    file_dialog_complete_handler: fileDialogComplete,
    //    upload_start_handler: uploadStart,
    //    upload_progress_handler: uploadProgress,
    //    upload_error_handler: uploadError,
    //    upload_success_handler: EstateUploadSuccess,
    //    upload_complete_handler: uploadComplete,
    //    queue_complete_handler: queueComplete	// Queue plugin event
    //};
    //var swfu2 = new SWFUpload(settings);

    agencyVerify.notNullInput(null, "input[notnull=1]", false, "blur");
    agencyVerify.notdefaultSelect("#anjukeEdit", "#anjukeEdit #selExposure", -1, "朝向必填", true);
    agencyVerify.nonnegativeIntInput("input[isint=1]", true);
    agencyVerify.nonnegativeInput("input[isfloat=1]", true);
    agencyVerify.greaterThanZeroInput("input[greater-than-zero=1]", true);
    agencyVerify.zhengFuIntInput("#txtFloorNum");
    agencyVerify.zhengFuIntInput("#txtHallNum");
    $("#txtFloorNum,#txtHallNum").bind("keyup input paste blur", function () {
        if ((!$(this).val().match(/^(-|\+)?\d+$/)) || ($(this).val() == 0 || $(this).val().indexOf('0') == 0)) {
            $(this).removeClass("checkError").next(".wrong").remove();
            $(this).addClass("checkError").after(agencyVerify.greatErrorHtml($(this), '楼层必须是非零整数！'));
        }
        else {
            $(this).removeClass("checkError").next(".wrong").remove();
            if (parseInt($("#txtFloorNum").val(), 10) > parseInt($("#txtHallNum").val(), 10)) {
                $(this).removeClass("checkError").next(".wrong").remove();
                $(this).addClass("checkError").after(agencyVerify.greatErrorHtml($(this), '楼层必须小于等于总楼层！'));
            }
            else {
                if (parseInt($("#txtFloorNum").val(), 10) > 127 || parseInt($("#txtHallNum").val(), 10) > 127) {
                    $(this).removeClass("checkError").next(".wrong").remove();
                    $(this).addClass("checkError").after(agencyVerify.greatErrorHtml($(this), '楼层必须小于等于127层！'));
                }
                else {
                    $(this).removeClass("checkError").next(".wrong").remove();
                }
            }
        }
    });

    $("#selectAll").unbind("click");
    $("#selectAll").bind("click", function () {
        var checkedCount = 0;
        $("#rent input[ad=ad]").each(function () {
            if ($(this).attr("checked") == "checked") {
                checkedCount = checkedCount + 1;
            }
        });
        //如果列表中都勾选了，则将全选设为勾选状态
        if ($("#rent input[ad=ad]").length == checkedCount) {
            $("#rent input[ad=ad]").each(function () {
                $(this).attr("checked", false);
            });
        }
        else if (checkedCount >= 0) {
            $("#rent input[ad=ad]").each(function () {
                $(this).attr("checked", true);
            });
        }
    });

    //点击【小区】、【户型】、【房屋结构】、【位置】、【装修】、【附加】
    $(".tab-hd ul li").each(function () {
        $(this).click(function () {
            if ($(this).attr("id") == "village") {
                $("#divVillage").show();
                $("#divApartmentLayout").hide();
                $("#divHousingStructure").hide();
                $("#divLocation").hide();
                $("#divRenovation").hide();
                $("#divAddition").hide();
            }
            else if ($(this).attr("id") == "apartmentLayout") {
                $("#divVillage").hide();
                $("#divApartmentLayout").show();
                $("#divHousingStructure").hide();
                $("#divLocation").hide();
                $("#divRenovation").hide();
                $("#divAddition").hide();
            }
            else if ($(this).attr("id") == "housingStructure") {
                $("#divVillage").hide();
                $("#divApartmentLayout").hide();
                $("#divHousingStructure").show();
                $("#divLocation").hide();
                $("#divRenovation").hide();
                $("#divAddition").hide();
            }
            else if ($(this).attr("id") == "location") {
                $("#divVillage").hide();
                $("#divApartmentLayout").hide();
                $("#divHousingStructure").hide();
                $("#divLocation").show();
                $("#divRenovation").hide();
                $("#divAddition").hide();
            }
            else if ($(this).attr("id") == "renovation") {
                $("#divVillage").hide();
                $("#divApartmentLayout").hide();
                $("#divHousingStructure").hide();
                $("#divLocation").hide();
                $("#divRenovation").show();
                $("#divAddition").hide();
            }
            else if ($(this).attr("id") == "addition") {
                $("#divVillage").hide();
                $("#divApartmentLayout").hide();
                $("#divHousingStructure").hide();
                $("#divLocation").hide();
                $("#divRenovation").hide();
                $("#divAddition").show();
            }
            $(this).siblings().removeClass("current");
            $(this).addClass("current");
        });
    });

    $("#btnAddTag").unbind("click");
    $("#btnAddTag").bind("click", function () {
        var txtTag = $("#txtTag");
        if (other.trim(txtTag.val()).length == 0) {
            $.OKDialogAgency('<center>请输入标签！</center>');
            txtTag.focus();
        }
        else {
            var url = "/Advert/add-property-tag";
            var reqData = {
                "propId": $("#hidAnJuKeId").val(),
                "propTags": other.trim(txtTag.val()),
                "commTags": other.trim(txtTag.val())
            };
            $.AjaxAgency(url, reqData, function (data) {
                if (data == "err") {
                    $.OKDialogAgency('<center>' + data + '</center>');
                }
                txtTag.val("");
            });
        }
    });

    //共享室内图
    $("#btnVillageShareImgs").unbind("click");
    $("#btnVillageShareImgs").bind("click", function () {
        var currentElement = $(this), photoTypeKeyId = '';
        currentElement.attr('disabled', 'true');
        for (var i = 0; i < SysParam.length; i++) {
            if (SysParam[i].ParameterType == 2) {
                for (var j = 0; j < SysParam[i].Items.length; j++) {
                    photoTypeKeyId += SysParam[i].Items[j].ItemValue + ",";
                }
                break;
            }
        }
        var reqData = {
            'anJuKeId': $("#hidAnJuKeId").val(),
            'photoTypeKeyId': photoTypeKeyId
        };
        $.AjaxAgency('/advert/village-share-imgs', reqData, function (data) {
            if (data) {
                $.dialog({
                    id: "village-shareMaps",
                    lock: true,
                    title: "室内图共享图库",
                    background: "#808080",
                    opacity: 0.87,
                    content: data
                });
            }
            currentElement.removeAttr('disabled');
        });
    });

    //共享户型图
    $("#btnRoomShareImgs").unbind("click");
    $("#btnRoomShareImgs").bind("click", function () {
        var currentElement = $(this), photoTypeKeyId = '';
        currentElement.attr('disabled', 'true');
        for (var i = 0; i < SysParam.length; i++) {
            if (SysParam[i].ParameterType == 56) {
                photoTypeKeyId += SysParam[i].Items[0].ItemValue;
                break;
            }
        }
        var reqData = {
            'propertyKeyId': $("#hidPropertyKeyId").val(),
            'anJuKeId': $("#hidAnJuKeId").val(),
            'photoTypeKeyId': photoTypeKeyId
        };
        $.AjaxAgency('/advert/room-type-share-imgs', reqData, function (data) {
            if (data) {
                $.dialog({
                    id: "room-shareMaps",
                    lock: true,
                    title: "平面共享图库",
                    background: "#808080",
                    opacity: 0.87,
                    content: data
                });
            }
            currentElement.removeAttr('disabled');
        });
    });

    //共享小区图
    $("#btnEsateShareImgs").unbind("click");
    $("#btnEsateShareImgs").bind("click", function () {
        var currentElement = $(this), photoTypeKeyId = '';
        currentElement.attr('disabled', 'true');
        for (var i = 0; i < SysParam.length; i++) {
            if (SysParam[i].ParameterType == 1) {
                photoTypeKeyId += SysParam[i].Items[0].ItemValue;
                break;
            }
        }
        var reqData = {
            'propertyKeyId': $("#hidPropertyKeyId").val(),
            'anJuKeId': $("#hidAnJuKeId").val(),
            'photoTypeKeyId': photoTypeKeyId
        };
        $.AjaxAgency('/advert/estate-type-share-imgs', reqData, function (data) {
            if (data) {
                $.dialog({
                    id: "estate-shareMaps",
                    lock: true,
                    title: "小区共享图库",
                    background: "#808080",
                    opacity: 0.87,
                    content: data
                });
            }
            currentElement.removeAttr('disabled');
        });
    });

    $("#btnSave").unbind("click");
    $("#btnSave").bind("click", function () {
        if ($(".wrong").length > 0) {
            return false;
        }
        if (!checkTitle()) {
            return false;
        }
        var hidType = $("#hidType").val();
        if (!checkDesc()) {
            return false;
        }
        var price = $("#txtPrice").val();

        var reqData;
        var equipment = "";
        var photoPaths = "";
        if (hidType == 2) {
            if ($("#cheHaveWater").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveElect").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveGas").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveWarm").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveTv").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveBroad").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveTvbox").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveRefr").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveAir").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveWash").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveHotwater").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveMicro").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
            if ($("#cheHaveTel").checked) {
                equipment = equipment + "1";
            }
            else {
                equipment = equipment + "0";
            }
        }
        if (hidType == 1) {
            price = price * 10000;
        }
        var photoPaths = "";
        $("input[name='AdvertPhotoPath']").each(function () {
            photoPaths += $(this).val() + ",";
        });

        var photoTypes = "";
        $("input[name='AdvertPhotoType']").each(function () {
            photoTypes += $(this).val() + ",";
        });
        
        var photoDescs = "";
        $("input[name='PhotoDesc']").each(function () {
            photoDescs += $(this).val() + ",";
        });
        if (hidType == 1) {
            reqData = {
                "ProId": $("#hidAnJuKeId").val(),
                "UserDefined": "",
                "TradeType": $("#hidType").val(),
                "Area": $("#txtArea").val(),
                "Rooms": $("#txtF").val() + "," + $("#txtT").val() + "," + $("#txtW").val(),
                "Price": price,
                "Floor": $("#txtFloorNum").val() + "," + $("#txtHallNum").val(),
                "Year": $("#txtHouseAge").val(),
                "Fitment": $("#selFitment").val(),
                "Style": $("#selStyle").val(),
                "Exposure": $("#selExposure").val(),
                "Title": $("#txtTitle").val(),
                "Desc": UM.getEditor('desc').getContent(),
                "Stype": 1,
                "PhotoPaths": photoPaths,
                "PhotoTypes": photoTypes,
                "PhotoDescs": photoDescs
            };
        }
        else {
            //stype 1=出售出租中,11=待上架
            reqData = {
                "ProId": $("#hidAnJuKeId").val(),
                "UserDefined": "",
                "TradeType": $("#hidType").val(),
                "Area": $("#txtArea").val(),
                "Rooms": $("#txtF").val() + "," + $("#txtT").val() + "," + $("#txtW").val(),
                "Price": price,
                "Floor": $("#txtFloorNum").val() + "," + $("#txtHallNum").val(),
                "Year": $("#txtHouseAge").val(),
                "Fitment": $("#selFitment").val(),
                "Style": $("#selStyle").val(),
                "Exposure": $("#selExposure").val(),
                "Title": $("#txtTitle").val(),
                "Desc": UM.getEditor('desc').getContent(),
                "Equipment": equipment,
                "RentDepositCycle": $("#selRentDepositCycle").val(),
                "ShareRent": true,
                "Stype": 1,
                "PhotoPaths": photoPaths,
                "PhotoTypes": photoTypes,
                "PhotoDescs": photoDescs
            };
        }
        $.AjaxAgency('/advert/update-property', reqData, function (data) {
            if (data == "ok") {
                $.OKDialogAgency('<center>修改成功！</center>');
            } else {
                $.OKDialogAgency('<center class="li-21 w510">' + data + '</center>');
            }

        });
    });
});

//删除操作
function delhxt(ctr) {
    var imgId = $(ctr).attr("imgId");
    $.OKCancelDialogAgency('<center>您确定要删除图片吗?</center>', '提示', true, function () {
        if ($("#uploadRoomTypeDiv").find("li").length==1) {
            $(".upload-property-pics-r p").show();
        }
        $(ctr).parent().remove();
        var reqData = {
            'imgId': imgId
        };
        $.AjaxAgency('/advert/anjuke-anjuke-delete', reqData, function (data) {
            if (data == "ok") {
                $.OKDialogAgency('<center>删除成功！</center>');
            }
        });
    }, null);
}

function setDefault(ctr) {
    $("#uploadRoomTypeDiv li a").text("设置橱窗");
    $("#uploadRoomTypeDiv li a").attr('onclick', 'setDefault(this)');
    $("#uploadRoomTypeDiv li").find("input[name='AdvertIsDefault']").attr('value', '0');
    $(ctr).text("橱窗图");
    $(ctr).removeAttr('onclick');
    $(ctr).next("input[name='AdvertIsDefault']").attr('value', '1');
}
function checkTitle() {
    var title = other.trim($("#txtTitle").val());
    //if (title.length == 0) {
    //    $.OKDialogAgency('<div class="tc">房源标题不能为空！</div>');
    //    return false;
    //}
    //else
    if (title.length < 5 && title.length > 0) {
        $.OKDialogAgency('<center>房源标题最少输入5个字！</center>');
        return false;
    }
    else if (title.length > 30) {
        $.OKDialogAgency('<center>房源标题最多输入30个字！</center>');
        return false;
    }
    else {
        return true
    }
}

function checkDesc() {
    //var description = other.trim($("#desc").val());
    var description = other.trim(UM.getEditor('desc').getContentTxt());
    //if (description.length == 0) {
    //    $.OKDialogAgency('<div class="tc">房源描述不能为空！</div>');
    //    return false;
    //}
    //else 
    var hidType = $("#hidType").val();
    if (hidType == 1) {
        if (description.length >= 20 && description.length <= 5000 && description.length > 0) {
            return true;
        }
        else {
            $.OKDialogAgency('<center>请输入20-5000个字的房源描述！</center>');
            return false;
        }
    } else {
        if (description.length <= 10 && description.length > 0) {
            $.OKDialogAgency('<center>请输入10个字以上的房源描述！</center>');
            return false;
        }
        else {
            return true;
        }
    }
}
